<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">

    @include('bend/common/js')

    <link rel="stylesheet" href="/art/css/base.css" media="all">
</head>

<body>


<div class="layui-fluid">

    <div class="layui-card borderradius">

        <!--- 搜索框 --->
        <form id="search-form" method="post" enctype="">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">学员姓名</label>
                        <div class="layui-input-block">
                            <input type="text" id="search-name" name="name" placeholder="请输入姓名" autocomplete="off"
                                   class="layui-input" value="{{$request['name']??''}}"
                                   style="width: 120px;">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">学员年龄</label>
                        <div class="layui-input-block">
                            <input type="text" id="search-age" name="age" placeholder="请输入数字" autocomplete="off"
                                   class="layui-input" value="{{$request['age']??''}}"
                                   style="width: 120px;">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">联系电话</label>
                        <div class="layui-input-block">
                            <input type="text" id="search-tell" name="tell" placeholder="请输入联系电话" autocomplete="off"
                                   class="layui-input" value="{{$request['tell']??''}}"
                                   style="width: 120px;">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">性别</label>
                        <div class="layui-input-block">
                            <select id="search-sex" name="sex" style="width: 120px;display: inline;"
                                    class="layui-input">
                                <option value="0" @if(empty($request['sex'])) selected @endif>不限</option>
                                <option value="1" @if(!empty($request['sex']) && ($request['sex']==1)) selected @endif>
                                    男
                                </option>
                                <option value="2" @if(!empty($request['sex']) && ($request['sex']==2)) selected @endif>
                                    女
                                </option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <button class="layui-btn layuiadmin-btn-useradmin search-submit" lay-submit
                                lay-filter="LAY-user-front-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </div>
        </form>

        <div class="layui-card-body">

            <!--- 顶部操作按钮 --->
            <div style="padding-bottom: 10px;">
                <button class="layui-btn layuiadmin-btn-useradmin" data-type="batchdel">删除</button>
                <button class="layui-btn layuiadmin-btn-useradmin" data-type="add">添加</button>
            </div>

            <!--- 列表展示 --->
            <table class="layui-table" id="LAY-user-manage" lay-filter="LAY-user-manage">

                <thead>
                <tr class="text-c">
                    <th width="25"><input type="checkbox" id="checkAll" name="" value=""></th>
                    <th>姓名</th>
                    <th>性别</th>
                    <th>年龄</th>
                    <th>监护人</th>
                    <th>手机号</th>
                    <th>状态</th>
                    <th>添加时间</th>
                    <th>操作</th>
                </tr>
                </thead>

                @foreach($list as $_row)
                    <tr>
                        <td><input type="checkbox" value="{{$_row['id']}}" name="id"/></td>
                        <td>{{$_row['person_name']}}</td>
                        <td>{{$_row['sex']}}</td>
                        <td>{{$_row['age']}}</td>
                        <td>{{$_row['guardor']}}</td>
                        <td>{{$_row['mobile']}}</td>
                        <td>{{$_row['status']==1?'接入':'未接入'}}</td>
                        <td>{{date('Y-m-d H:i', $_row['ctime'])}}</td>
                        <td>
                            <a class="layui-btn layui-btn-normal layui-btn-xs row-edit" lay-event="edit" data-id="{{$_row['id']}}">
                                <i class="layui-icon layui-icon-edit"></i>编辑
                            </a>
                            <a class="layui-btn layui-btn-danger layui-btn-xs row-del" lay-event="del" data-id="{{$_row['id']}}">
                                <i class="layui-icon layui-icon-delete"></i>删除
                            </a>
                        </td>
                    </tr>
                @endforeach
            </table>

            <!--- 列表操作 --->


        </div>

        <!--- 列表翻页 --->
        <div class="layui-col-md12 layui-col-sm12">
            <div id="demo0"></div>
        </div>
        <div class="page"></div>
        <div id="LAY-template-search-page" style="text-align: center;"></div>

    </div>

</div>
{{--include('bend/common/lists_js')--}}

<script>
    var encodeConfig = {!! json_encode($encodeConfig) !!};

    // 搜索数据
    function getSearch() {
        let searchs = {};
        searchs['name'] = $("#search-name").val();
        searchs['age'] = $("#search-age").val();
        searchs['tell'] = $("#search-tell").val();
        searchs['sex'] = $("#search-sex").val();

        return searchs
    }

    // 搜索
    $(".search-submit").on('click', function () {
        var formObj = $("#search-form");

        formObj.action = "/bend/student/lists"; // 发送请求的路径
        formObj.method = "post";  // 表单请求的方式
        formObj.attr('action', "/bend/student/lists")

        //如果不设置上面的两个参数，默认提交触发该事件的表单
        formObj.submit();  //表单提交

        return false;
    })

    // 编辑
    $('.row-edit').on('click', function () {
        let _id = $(this).data('id');
        console.log('编辑的id', _id)

        // 打开页面
        layer.open({
            type: 2
            , title: '添加我的学员'
            , content: '/bend/student/edit.html?student_id='+_id
            , maxmin: true
            , area: ['800px', '580px']
            //, btn: ['确定', '取消']
            , yes: function (index, layero) {

            }
        });

        //执行 Ajax 后重载
       /* enAjax('/bend/student/on-delete', encodeConfig, {id: _id},
            function (ret) {
                layer.msg(ret.msg, {icon: 6, time: 2000});
                if (ret.code === 200) {
                    layer.confirm('确定删除吗？', function (index) {
                        //执行 Ajax 后重载

                        // 刷新页面
                        layer.msg('已删除');
                        setTimeout(function () {
                            window.location.href = '/bend/student/lists';
                        },2000)
                    });
                } else {
                    // 验证失败

                }
            })*/
    })

    // 删除
    $('.row-del').on('click', function () {
        let _id = $(this).data('id');
        console.log('删除的id', _id)

        layer.prompt({
            formType: 1
            , title: '敏感操作，请验证口令'
        }, function (value, index) {
            console.log('输入的密码', value)
            console.log('删除的id', _id)
            // 验证密码
            enAjax('/bend/student/check-password', encodeConfig, {password: value},
                function (ret) {
                    layer.close(index)
                    if (ret.code === 200) {
                        layer.confirm('确定删除吗？', function (index) {
                            //执行 Ajax 后重载
                            enAjax('/bend/student/on-delete', encodeConfig, {id: _id},
                                function (ret) {
                                    layer.msg(ret.msg, {icon: 6, time: 2000});
                                    if (ret.code === 200) {
                                        layer.confirm('确定删除吗？', function (index) {
                                            //执行 Ajax 后重载

                                            // 刷新页面
                                            layer.msg('已删除');
                                            setTimeout(function () {
                                                window.location.href = '/bend/student/lists';
                                            },2000)
                                        });
                                    } else {
                                        // 验证失败

                                    }
                                })
                        });
                    } else {
                        // 验证失败
                        layer.msg(ret.msg, {icon: 6, time: 2000});
                    }
                }
            )
        });
    })





    /*layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        //index: 'lib/index' //主入口模块
    }).use(['index', 'useradmin', 'table'], function () {

        //事件
        var active = {
            batchdel: function () {
                var checkStatus = table.checkStatus('LAY-user-manage')
                    , checkData = checkStatus.data; //得到选中的数据

                if (checkData.length === 0) {
                    return layer.msg('请选择数据');
                }

                layer.prompt({
                    formType: 1
                    , title: '敏感操作，请验证口令'
                }, function (value, index) {
                    layer.close(index);
                    layer.confirm('确定删除吗？', function (index) {
                        //执行 Ajax 后重载
                        /!*
                        admin.req({
                          url: 'xxx'
                          //,……
                        });
                        *!/
                        table.reload('LAY-user-manage');
                        layer.msg('已删除');
                    });
                });
            }

            , add: function () {
                layer.open({
                    type: 2
                    , title: '添加我的学员'
                    , content: 'addstudent.html'
                    , maxmin: true
                    , area: ['300px', '380px']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index]
                            , submitID = 'LAY-user-front-submit'
                            , submit = layero.find('iframe').contents().find('#' + submitID);

                        //监听提交
                        iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                            var field = data.field; //获取提交的字段
                            //提交 Ajax 成功后，静态更新表格中的数据
                            //$.ajax({});
                            table.reload('LAY-user-front-submit'); //数据刷新
                            layer.close(index); //关闭弹层
                        });
                        submit.trigger('click');
                    }
                });
            }
        };


        $('.layui-btn.layuiadmin-btn-useradmin').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });*/

</script>

</body>

</html>

